<?php
class MailsController 
	extends Zend_Controller_Action 
{
	
	public function sendAction()
	{
//		try {

		//Mails
	    $mapper = Delivery_Model_Factory::mapper('MailsQueue');
	    $mailer = new Delivery_Model_Mailer;
	    $config = Zend_Registry::get("configuration");
	    
		$mailsQueue = $mapper->getAll(10);
		
		foreach ( $mailsQueue as $mailQueue){
		
		    $mailer->send( $mailQueue );
		    $mapper->delete( $mailQueue );
		}
		
		
		//Sms
	    $mapperSms = Delivery_Model_Factory::mapper('QueueSms');
	    
		$queueSmsCollection = $mapperSms->getAll( 10 );
		
		$sms = $config->sms;
		
		foreach ( $queueSmsCollection as $queueSms){
		
		    $mailer->sendSms( $sms->host, $sms->user, $sms->pass, $sms->from, $queueSms);
		    $mapperSms->delete( $queueSms );
		}
		
		echo "Terminado";
		
//		} catch (Zend_Exception $e){
//			$this->getHelper('Log')->exception( $e );
//		}
		
	}
	
}